package com.atguigu.classroom.live.controller;


import com.atguigu.classroom.live.service.LiveCourseAccountService;
import com.atguigu.classroom.live.service.LiveCourseConfigService;
import com.atguigu.classroom.live.service.LiveCourseService;
import com.atguigu.classroom.model.live.LiveCourse;
import com.atguigu.classroom.model.live.LiveCourseAccount;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.live.LiveCourseConfigVo;
import com.atguigu.classroom.vo.live.LiveCourseFormVo;
import com.atguigu.classroom.vo.live.LiveCourseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 直播课程表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-07-26
 */
@Api(tags = "直播课程接口")
@RestController
@RequestMapping("/admin/live/liveCourse/")
public class LiveCourseController {
    @Autowired
    private LiveCourseService liveCourseService;
    @Autowired
    private LiveCourseAccountService liveCourseAccountService;
    @Autowired
    private LiveCourseConfigService liveCourseConfigService;

    @ApiOperation("分页查询课程方法")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable int page,@PathVariable int limit){
        Page<LiveCourse> liveCoursePage=liveCourseService.selectPage(page,limit);
        return Result.ok(liveCoursePage);
    }

    @ApiOperation("直播课程添加")
    @PostMapping("save")//注意，设置直播时长不可超过24h
    public Result saveLiveCourse(@RequestBody LiveCourseFormVo liveCourseFormVo){
        liveCourseService.saveLiveCourse(liveCourseFormVo);
        return Result.ok(null);
    }

    @ApiOperation(value = "直播课程删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        liveCourseService.deleteLiveCourse(id);
        return Result.ok(null);
    }

    @ApiOperation(value = "id查询直播课程基本信息")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        LiveCourse liveCourse = liveCourseService.getById(id);
        return Result.ok(liveCourse);
    }

    @ApiOperation(value = "id查询直播课程基本信息和描述信息和密码信息")
    @GetMapping("getInfo/{id}")
    public Result getInfo(@PathVariable Long id) {
        LiveCourseFormVo liveCourseFormVo=liveCourseService.getLiveCourseFormVo(id);
        return Result.ok(liveCourseFormVo);
    }

    @ApiOperation(value = "修改直播课程信息")
    @PutMapping("update")
    public Result updateById(@RequestBody LiveCourseFormVo liveCourseFromVo) {
        liveCourseService.updateLiveCourseFromVoById(liveCourseFromVo);
        return Result.ok(null);
    }

    @ApiOperation(value = "获取直播账号信息")
    @GetMapping("getLiveCourseAccount/{id}")
    public Result getLiveCourseAccount(@PathVariable Long id) {
        LiveCourseAccount liveCourseAccount=liveCourseAccountService.getLiveCourseAccountByLiveCourseId(id);
        return Result.ok(liveCourseAccount);
    }

    @ApiOperation(value = "获取直播配置信息")
    @GetMapping("getCourseConfig/{id}")
    public Result getCourseConfig(@PathVariable Long id) {
        LiveCourseConfigVo liveCourseConfigVo=liveCourseConfigService.getLiveCourseConfigByLiveCourseId(id);
        return Result.ok(liveCourseConfigVo);
    }

    @ApiOperation(value = "修改直播配置信息")
    @PutMapping("updateConfig")
    public Result updateConfig(@RequestBody LiveCourseConfigVo liveCourseConfigVo) {
        liveCourseConfigService.updateOrAddConfig(liveCourseConfigVo);
        return Result.ok(null);
    }

    @ApiOperation(value = "获取最近的直播")
    @GetMapping("findLatelyList")
    public Result findLatelyList() {
        List<LiveCourseVo> latelyList=liveCourseService.findLatelyList();
        return Result.ok(latelyList);
    }
}

